<template>
  <div class="ele-body">
    <el-row :gutter="15">
      <el-col :md="24" :sm="24">
        <el-card shadow="never" body-style="padding-top: 5px;">
          <el-tabs v-model="active" class="user-info-tabs">
            <el-tab-pane label="短信配置" name="info">
              <el-form
                ref="smsConfig"
                :model="form"
                :rules="rules"
                label-width="90px"
                style="max-width: 450px;padding-top: 40px;"
                @keyup.enter.native="save"
                @submit.native.prevent>
                <el-form-item label="AppKey:" prop="AppKey" >
                  <el-input
                    v-model="form.AppKey"
                    placeholder="请输入AppKey"
                    clearable/>
                </el-form-item>
                <el-form-item label="SecretKey:" prop="SecretKey">
                  <el-input
                    v-model="form.SecretKey"
                    placeholder="请输入SecretKey"
                    clearable/>
                </el-form-item>
                <el-form-item label="接口地址:" prop="ApiUrl">
                  <el-input
                    v-model="form.ApiUrl"
                    placeholder="请输入ApiUrl"
                    clearable/>
                </el-form-item>
                <el-form-item  >
                  <el-button
                    type="primary"
                    @click="save"
                    :loading="loading" v-if="permission.includes('sys:channel:edit')">保存更改
                  </el-button >
                </el-form-item>
              </el-form>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import setting from '@/config/setting';
import {mapGetters} from "vuex";

export default {
  name: 'SmsConfig',
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      active: 'info',
      // 表单数据
      form: {},
      // 表单验证规则
      rules: {
        AppKey: [
          {required: true, message: '请输入AppKey', trigger: 'blur'}
        ],
        SecretKey: [
          {required: true, message: '请输入SecretKey', trigger: 'blur'}
        ],
        ApiUrl: [
          {required: true, message: '请输入ApiUrl', trigger: 'blur'}
        ],
      },
      // 保存按钮loading
      loading: false,
      // 是否显示裁剪弹窗
      showCropper: false
    };
  },
  mounted() {
    // 获取用户信息
    this.getUserInfo();
  },
  methods: {
    /* 获取当前用户信息 */
    getUserInfo() {
      // if ('/smsconfig/index') {
        this.$http.get('/admin/config.smsconfig/index').then((res) => {
          const result = setting.parseUser ? setting.parseUser(res.data) : res.data;
          if (result.code === 0) {
            // 赋予对象值
            console.log(result.data)
            this.form = JSON.parse(JSON.stringify(result.data))
            console.log(this.form)
          } else {
            this.$message.error(result.msg);
          }
        }).catch((e) => {
          console.error(e);
          this.$message.error(e.message);
        });
      // }
    },
    /* 保存更改 */
    save() {
      this.$refs['smsConfig'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http.post('/admin/platform.smscofing/edit', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success('保存成功');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    }
  }
}
</script>

<style scoped>
.ele-body {
  padding-bottom: 0;
}

.el-card {
  margin-bottom: 15px;
}

/* 用户资料卡片 */
.user-info-card {
  padding-top: 8px;
  text-align: center;
}

.el-input {
  width: 600px;
}

.user-info-card .user-info-avatar-group {
  position: relative;
  cursor: pointer;
  margin: 0 auto;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  overflow: hidden;
}

.user-info-card .user-info-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
}


.user-info-list .user-info-item {
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
}

.user-info-item > i {
  margin-right: 10px;
  font-size: 16px;
}

.user-info-item > span {
  flex: 1;
  display: block;
}

/* 用户标签 */
.user-info-tags .el-tag {
  margin: 10px 10px 0 0;
}

/* 用户账号绑定列表 */
.user-account-list {
  margin-top: 10px;
}

.user-account-list .user-account-item {
  padding: 15px;
}

.user-account-list .user-account-item .ele-text-secondary {
  margin-top: 6px;
}

.user-account-list .user-account-item .user-account-icon {
  width: 42px;
  height: 42px;
  line-height: 42px;
  text-align: center;
  color: #FFF;
  font-size: 26px;
  border-radius: 50%;
  background-color: #3492ED;
  box-sizing: border-box;
}

.user-account-list .user-account-item .user-account-icon.el-icon-_wechat {
  background-color: #4DAF29;
  font-size: 28px;
}

.user-account-list .user-account-item .user-account-icon.el-icon-_alipay {
  background-color: #1476FE;
  padding-left: 5px;
  font-size: 32px;
}

/* tab页签 */
.user-info-tabs ::v-deep .el-tabs__nav-wrap {
  padding-left: 20px;
}
</style>
